home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / SOUND / CRYS270.ZIP / GUS.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-06-26  |  12.9 KB  |  946 lines

  1. ;***************************************************************************
  2. ;*    Driver pour la GUS
  3. ;*
  4. ;* Programmé par Sébastien Granjoux
  5. ;* Commencé le 07/01/95
  6. ;* Modification le 07/01/95
  7.  
  8. IDEAL
  9. P386N
  10.  
  11. INCLUDE "CRYSLOAD.INC"
  12. INCLUDE "CRYSERR.INC"
  13. INCLUDE "CRYSDEV.INC"
  14.  
  15. PUBLIC    USEGUS
  16.  
  17. SEGMENT CODE PARA PUBLIC USE16 'CODE'
  18.  
  19. ASSUME cs:CODE,ds:CODE
  20.  
  21. ;*************************************************************************
  22. ;*    Fonction de detection du driver
  23.  
  24. PROC    USEGUS
  25.  
  26.     call    USEDEVICE
  27.     DEVICE <4,'ULTRASNDs=p,d,i$',OFFSET setgus,OFFSET startgus,OFFSET stopgus,OFFSET makegus,OFFSET defbpmgus,OFFSET peekgus,0,0,0>
  28.  
  29. ENDP
  30.  
  31. RAMPDELAY    EQU    4A9h
  32.  
  33. Compteur    DD    0
  34. Compte        DD    0
  35. BPMspeed    DW    0
  36.  
  37. STRUC GUSDATA
  38.  
  39.     action        DB    ?
  40.             DW      ?
  41.             DB      ?
  42.     note        DW    ?
  43.     volume        DW    ?
  44.     repadr        DD    ?
  45.     endadr        DD    ?
  46.     curadr        DD    ?
  47.             DD    ?
  48.             DD    ?
  49.             DD    ?
  50.  
  51. ENDS
  52.  
  53. GusMem    DD    0
  54. GusSample DD MAX_INST DUP (?)    ; Adresse des samples dans la mémoire de la GUS
  55.  
  56. ;***************************************************************************
  57. ;*    Routine permettant d'écrire un octet dans la GUS
  58. ;*
  59. ;* Entrée:
  60. ;*    DX    adresse de port de la GUS
  61. ;*    EBX    adresse où écrire
  62. ;*    AL    donné à écrire
  63.  
  64. PROC    putgus
  65.  
  66.     push    cx
  67.  
  68.     mov    cl,al
  69.     mov    al,43h
  70.     out    dx,al
  71.  
  72.     inc    dx
  73.     mov    eax,ebx
  74.     out    dx,ax
  75.  
  76.     dec    dx
  77.     mov    al,44h
  78.     out    dx,al
  79.  
  80.     add    dx,2
  81.     shr    eax,16
  82.     out    dx,al
  83.  
  84.     add    dx,2
  85.     mov    al,cl
  86.     out    dx,al
  87.  
  88.     sub    dx,4
  89.  
  90.     pop    cx
  91.  
  92.     ret
  93.  
  94. ENDP
  95.  
  96. ;***************************************************************************
  97. ;*    Routine permettant de lire un octet de la RAM de la GUS
  98. ;*
  99. ;* Entrée:
  100. ;*    DX    adresse de port de la GUS
  101. ;*    EBX    adresse à lire
  102. ;*
  103. ;* Sortie:
  104. ;*    AL    octet lus
  105.  
  106. PROC    getgus
  107.  
  108.     mov    al,43h
  109.     out    dx,al
  110.  
  111.     inc    dx
  112.     mov    eax,ebx
  113.     out    dx,ax
  114.  
  115.     dec    dx
  116.     mov    al,44h
  117.     out    dx,al
  118.  
  119.     add    dx,2
  120.     shr    eax,16
  121.     out    dx,al
  122.  
  123.     add    dx,2
  124.     in    al,dx
  125.  
  126.     sub    dx,4
  127.  
  128.     ret
  129.  
  130. ENDP
  131.  
  132. ;***************************************************************************
  133. ;*    Envoit une commande à la GUS
  134. ;*
  135. ;* Entrée:
  136. ;*    DX    adresse de port de la GUS
  137. ;*    AL    commande à envoyer
  138. ;*    AH    argument de la commande
  139.  
  140. PROC    putcom
  141.  
  142.  
  143.     out    dx,al
  144.  
  145.     add    dx,2
  146.     mov    al,ah
  147.     out    dx,al
  148.  
  149.     sub    dx,2
  150.  
  151.     ret
  152.  
  153. ENDP
  154.  
  155. ;***************************************************************************
  156. ;*    Routine d'initialisation de la GUS
  157.  
  158. PROC    setgus
  159.  
  160.     add    [(DEVICE ptr ds:si).port],103h
  161.     mov    dx,[(DEVICE ptr ds:si).port]
  162.  
  163.     mov    ax,4ch        ;Reset de la GUS
  164.     call    putcom
  165.  
  166.     add    dx,4
  167.     REPT    14
  168.     in    al,dx
  169.     ENDM
  170.     sub    dx,4
  171.  
  172.     mov    ax,14ch
  173.     call    putcom
  174.  
  175.     add    dx,4
  176.     REPT    14
  177.     in    al,dx
  178.     ENDM
  179.     sub    dx,4
  180.  
  181.     xor    ebx,ebx        ; Test la mémoire de la GUS
  182. @@test_mem:
  183.  
  184.     mov    al,0AAh        ; Ecrit 55AAh en 00000h
  185.     call    putgus
  186.     inc    ebx
  187.     mov    al,055h
  188.     call    putgus
  189.  
  190.     call    getgus        ; Lit 16 bits en 00000h
  191.     mov    ch,al
  192.     dec    ebx
  193.     call    getgus
  194.     mov     cl,al
  195.  
  196.     add    ebx,256*1024
  197.     cmp    ebx,(1024+256)*1024
  198.     je    @@enough_mem
  199.     cmp    cx,55aah
  200.     je    @@test_mem
  201.  
  202. @@enough_mem:
  203.     sub    ebx,256*1024
  204.     mov    [GusMem],ebx
  205.     jnz    @@find_gus
  206.  
  207.     mov    ax,GUS_NOT_FOUND    ;Pas de gus
  208.     stc
  209.     ret
  210.  
  211. @@find_gus:
  212.  
  213.     mov    [ds:MixRate],4400
  214.     mov    [(DEVICE PTR ds:si).irq],0
  215.     mov    [(DEVICE ptr ds:si).port],dx
  216.     mov    [ds:OFFSET port_gus1+1],dx
  217.     mov    [ds:OFFSET port_gus2+1],dx
  218.  
  219.     mov    ax,0041h    ; couche le DMA
  220.     call    putcom
  221.  
  222.     mov    ax,0045h    ; couche les timers
  223.     call    putcom
  224.  
  225.     mov    ax,0049h    ; pas de sampling
  226.     call    putcom
  227.  
  228.     mov    ax,0cd0eh
  229.     call    putcom
  230.  
  231.     mov    [ds:MixRate],4410
  232.     mov    al,SIZE GUSDATA            ;32*nombre de voix
  233.     mov    cl,[byte ptr ds:OFFSET NbVoice]
  234.     mul    cl
  235.     mov    [ds:VoicesLen],ax
  236.  
  237.     push    si
  238.  
  239.     mov    si,OFFSET Instrument1
  240.     mov    di,OFFSET GusSample+4
  241.     xor    ebx,ebx
  242.     mov    cl,MAX_INST
  243. @@next_inst:
  244.     push    cx
  245.  
  246.     mov    [ds:di],ebx
  247.     push    di
  248.     push    si
  249.  
  250.     mov    ax,[(INSTRUMENT ptr ds:si).adrseg]
  251.     mov    es,ax
  252.     xor    di,di
  253.     mov    cx,[(INSTRUMENT ptr ds:si).length]
  254.  
  255.     or    cx,cx
  256.     je    @@no_inst
  257.  
  258.     add    cx,SAMPLE_BORDER
  259.  
  260.     xor    si,si
  261. @@next_byte:
  262.     lods    [byte ptr es:si]
  263.     call    putgus
  264.     inc    ebx
  265.     dec    cx
  266.     jne    @@next_byte
  267.  
  268. @@no_inst:
  269.     pop    si
  270.     pop    di
  271.     pop    cx
  272.  
  273.     add    si,SIZE INSTRUMENT
  274.     add    di,4
  275.  
  276.     dec    cl
  277.     jne    @@next_inst
  278.  
  279.     cmp    ebx,[GusMem]
  280.     ja    @@not_enough_mem
  281.  
  282.     mov    ax,ds
  283.     mov    es,ax
  284.     mov    di,OFFSET VolumeTab    ; remplit la table de volume
  285.     mov    dx,7            ; valeur intial
  286. @@fill_tab:
  287.  
  288.     mov    ax,dx
  289.     or    ah,ah
  290.     mov    ah,15
  291.     jnz    @@find_dec
  292. @@next_dec:
  293.     dec    ah
  294.     shl    al,1
  295.     jnc    @@next_dec
  296. @@find_dec:
  297.     shl    ax,4
  298.     stosw
  299.     add    dx,4            ; coefficiant
  300.     cmp    di,OFFSET VolumeTab+65*2
  301.     jbe    @@fill_tab
  302.     pop    si
  303.  
  304.  
  305.     clc
  306.  
  307.     ret
  308.  
  309. @@not_enough_mem:
  310.  
  311.     mov    ax,NOT_ENOUGH_GUS
  312.     pop    bx
  313.     stc
  314.     ret
  315. ENDP
  316.  
  317.  
  318.  
  319. ;***************************************************************************
  320. ;*    Commence à envoyer les données sur la GUS
  321.  
  322. PROC startgus
  323.  
  324.     mov    dx,[(DEVICE ptr ds:si).port]
  325.  
  326.     mov    ch,31
  327. @@next_voices:
  328.     dec    dx
  329.     mov    al,ch
  330.     out    dx,al
  331.     inc    dx
  332.  
  333.     mov    ax,0800h    ; 800h loop enable
  334.     call    putcom        ; voice mode
  335.  
  336.     mov    cl,ch
  337.     inc    cl
  338.     and    cl,1
  339.     mov    ax,030ch
  340.     jz    @@right
  341.     mov    ah,0Ch
  342. @@right:
  343.     call    putcom        ; pan register 3 et 12
  344.  
  345.     mov    ax,20dh        ; stop les volumes ramps
  346.     call    putcom
  347.  
  348.     mov    ax,3f06h    ;changement de volume rapide
  349.     call    putcom
  350.  
  351.     mov    al,9
  352.     out    dx,al        ; volume à 0
  353.     inc    dx
  354.     xor    ax,ax
  355.     out    dx,ax
  356.     dec    dx
  357.  
  358.     dec    ch
  359.     jge    @@next_voices
  360.  
  361.     mov    ax,34ch        ;Allume le haut parleur
  362.     call    putcom
  363.  
  364.     sub    dx,103h
  365.     mov    al,1h
  366.     out    dx,al
  367.     add    dx,103h
  368.  
  369.     mov    [word ptr cs:OFFSET gus_switch+1],OFFSET soundgus1-OFFSET gus_switch+3
  370.  
  371.     cli
  372.     mov    ax,OFFSET soundgus
  373.     mov    dx,cs
  374.     xor    bl,bl
  375.     call    setirq
  376.  
  377.     mov    al,00110110b  ;00110110b
  378.     out     43h,al
  379.  
  380.     mov    ax,[BPMspeed]        ; interruption a 50Hz
  381.     out     40h,al
  382.     rol     ax,8
  383.     out     40h,al
  384.     rol    ax,8
  385.  
  386.     movzx    ecx,ax
  387.     mov    eax,80000000h
  388.     xor    edx,edx
  389.     div    ecx
  390.     add    eax,eax
  391.     mov    [ds:Compteur],eax
  392.     mov    [ds:Compte],eax
  393.  
  394.     call    setautoeoi
  395.     sti
  396.  
  397.     ret
  398.  
  399. ENDP
  400.  
  401. ;***************************************************************************
  402. ;*    Procédure qui place les données du son dans le buffer
  403.  
  404. PROC    makegus FAR
  405.  
  406.     mov    cl,[NbVoice]
  407.     mov    di,OFFSET Voice1
  408.     mov    si,[ds:OFFSET SoundPage]
  409. @@next_voice:
  410.     push    cx
  411.  
  412.     mov     dx,[(VOICE ptr ds:di).effet]
  413.     call    dx
  414.  
  415.     mov    bx,[(VOICE ptr ds:di).play]
  416.     add    bx,bx
  417.     mov    dx,[word ptr ds:bx+OFFSET Notes]
  418.     mov    [(GUSDATA ptr ds:si+OFFSET SoundBuf).note],dx
  419.  
  420.     mov      al,[MasterVol]
  421.     and    al,[(VOICE ptr ds:di).mute]
  422.     mul    [(VOICE ptr ds:di).volume]
  423.     mov    bl,ah
  424.     xor    bh,bh
  425.     shl    bx,1
  426.     mov    ax,[OFFSET VolumeTab+bx]
  427.     mov    [(GUSDATA ptr ds:si+OFFSET SoundBuf).volume],ax
  428.  
  429.     mov    bl,[(VOICE ptr ds:di).inst]
  430.     and    bx,1fh
  431.     mov    [(VOICE ptr ds:di).inst],bl
  432.     shl    bx,2
  433.     mov    ch,[(VOICE ptr ds:di).gusinf]
  434.     mov    [(VOICE ptr ds:di).gusinf],0
  435.     mov    [(GUSDATA ptr ds:si+OFFSET SoundBuf).action],ch
  436.  
  437.     test    ch,01h
  438.     jz    @@no_loadadr1
  439.  
  440.     xor    eax,eax
  441.     mov    ax,[(VOICE ptr ds:di).samplen]
  442.     add    eax,[ds:bx+OFFSET GusSample]
  443.     mov    [(GUSDATA ptr ds:si+OFFSET SoundBuf).endadr],eax
  444.  
  445.     xor    eax,eax
  446.     mov    ax,[(VOICE ptr ds:di).samplen]
  447.     sub    ax,[(VOICE ptr ds:di).replen]
  448.     add    eax,[ds:bx+OFFSET GusSample]
  449.     mov    [(GUSDATA ptr ds:si+OFFSET SoundBuf).repadr],eax
  450.  
  451. @@no_loadadr1:
  452.  
  453.     test    ch,02h
  454.     jz    @@no_loadcur1
  455.  
  456.     mov    eax,[(dword ptr (VOICE ptr ds:di).adrvoc)]
  457.     and    eax,0ffffh
  458.     add    eax,[ds:bx+OFFSET GusSample]
  459.     mov    [(GUSDATA ptr ds:si+OFFSET SoundBuf).curadr],eax
  460.  
  461. @@no_loadcur1:
  462.  
  463.     add    si,SIZE GUSDATA
  464.     add    di,SIZE VOICE
  465.     pop    cx
  466.     dec    cl
  467.     jne    @@next_voice
  468.  
  469.     and    si,65535-BUF_LEN
  470.     mov    [word ptr ds:OFFSET SoundPage],si
  471.     mov    [byte ptr cs:OFFSET switch_makemod],1Eh
  472.  
  473.     pop    edi
  474.     pop    esi
  475.     pop    ebp
  476.     pop    es
  477.     pop    ds
  478.  
  479.     ret
  480.  
  481.  
  482. ENDP
  483.  
  484.  
  485. ;***************************************************************************
  486. ;*      interruption 8 permettant d'envoyer le son sur la gus
  487.  
  488. PROC    soundgus FAR
  489.  
  490.     push    eax
  491.     push    bx
  492.     push    cx
  493.     push    dx
  494.  
  495. gus_switch:
  496.     jmp    soundgus2
  497.  
  498. soundgus1:
  499.     mov    ax,RAMPDELAY        ; interruption à 1kHz
  500.     out     40h,al
  501.     mov     al,ah
  502.     out     40h,al
  503.  
  504.     mov    [word ptr cs:OFFSET gus_switch+1],OFFSET soundgus2-OFFSET gus_switch+3
  505.  
  506.     mov    bx,[cs:OFFSET SoundPtr]
  507.  
  508. port_gus1:
  509.     mov    dx,323h
  510.  
  511.     mov    cl,[byte ptr cs:OFFSET NbVoice]
  512.     dec    cl
  513. @@next_voice:
  514.     dec    dx
  515.     mov    al,cl
  516.     out    dx,al
  517.  
  518.     inc    dx
  519.  
  520.     test    [(GUSDATA ptr cs:bx+OFFSET SoundBuf).action],4
  521.     jz    @@no_voice_off
  522.  
  523.     mov    al,09h
  524.     out    dx,al
  525.  
  526.     inc    dx
  527.     mov    al,[cs:OFFSET VolumeTab]
  528.     out    dx,al
  529.     dec    dx
  530.  
  531.     mov    al,89h
  532.     out    dx,al
  533.  
  534.     add    dx,2
  535.     in    al,dx
  536.     mov    ah,al
  537.     sub    dx,2
  538.  
  539.     mov    al,7
  540.     out    dx,al
  541.  
  542.     xor    al,al
  543.     mov    ch,[cs:OFFSET VolumeTab+1]
  544.  
  545.     cmp    ch,ah
  546.     ja    @@inc_vol
  547.     mov    al,40h
  548.     xchg    ch,ah
  549. @@inc_vol:
  550.  
  551.     add    dx,2
  552.     xchg    al,ah
  553.     out    dx,al
  554.     sub    dx,2
  555.  
  556.     mov    al,8
  557.     out    dx,al
  558.  
  559.     add    dx,2
  560.     mov    al,ch
  561.     out    dx,al
  562.     sub    dx,2
  563.  
  564.     mov    al,0dh
  565.     out    dx,al
  566.  
  567.     add    dx,2
  568.     mov    al,ah
  569.     out    dx,al
  570.     sub    dx,2
  571.  
  572. @@no_voice_off:
  573.  
  574.     add    bx,SIZE GUSDATA
  575.  
  576.     dec    cl
  577.     jns    @@next_voice
  578.  
  579.     pop    dx
  580.     pop    cx
  581.     pop    bx
  582.  
  583.     dec    [word cs:OFFSET Compte+2]
  584.     jz    @@int08
  585.  
  586.     pop    eax
  587.     iret
  588.  
  589. @@int08:
  590.     mov    eax,[cs:Compteur]
  591.     add    [cs:OFFSET Compte],eax
  592.     pop    eax
  593.     jmp    [dword ptr cs:OldIrq]
  594.  
  595.  
  596. soundgus2:
  597.     mov    ax,[cs:BPMspeed]    ; interruption à 50Hz
  598.     out     40h,al
  599.     mov     al,ah
  600.     out     40h,al
  601.  
  602.     mov    [word ptr cs:OFFSET gus_switch+1],OFFSET soundgus1-OFFSET gus_switch+3
  603.  
  604.     mov    bx,[cs:OFFSET SoundPtr]
  605.  
  606. port_gus2:
  607.     mov    dx,323h
  608.  
  609.     mov    cl,[byte ptr cs:OFFSET NbVoice]
  610.     dec    cl
  611. @@next_voice2:
  612.     dec    dx
  613.     mov    al,cl
  614.     out    dx,al
  615.  
  616.     inc    dx
  617.  
  618.     mov    ch,[(GUSDATA ptr cs:bx+OFFSET SoundBuf).action]
  619.  
  620.     test    ch,1
  621.     jz    @@no_new_inst
  622.  
  623.     mov    al,05h
  624.     out    dx,al
  625.  
  626.     inc    dx
  627.     mov    eax,[(GUSDATA ptr cs:bx+OFFSET SoundBuf).endadr]
  628.     rol    eax,9
  629.     out    dx,ax
  630.     dec    dx
  631.  
  632.     mov    al,04h
  633.     out    dx,al
  634.  
  635.     inc    dx
  636.     ror    eax,16
  637.     out    dx,ax
  638.     dec    dx
  639.  
  640.     mov    al,03h
  641.     out    dx,al
  642.  
  643.     inc    dx
  644.     mov    eax,[(GUSDATA ptr cs:bx+OFFSET SoundBuf).repadr]
  645.     rol    eax,9
  646.     out    dx,ax
  647.     dec    dx
  648.  
  649.     mov    al,02h
  650.     out    dx,al
  651.  
  652.     inc    dx
  653.     ror    eax,16
  654.     out    dx,ax
  655.     dec    dx
  656.  
  657. @@no_new_inst:
  658.  
  659.     test    ch,2
  660.     jz    @@no_loadcur
  661.  
  662.     mov    al,0
  663.     out    dx,al
  664.  
  665.     add    dx,2
  666.     mov    al,3
  667.     out    dx,al
  668.     sub    dx,2
  669.  
  670.     REPT    6
  671.     in    al,dx
  672.     ENDM
  673.  
  674.     add    dx,2
  675.     mov    al,3
  676.     out    dx,al
  677.     sub    dx,2
  678.  
  679.     mov    al,0bh
  680.     out    dx,al
  681.  
  682.     inc    dx
  683.     mov    eax,[(GUSDATA ptr cs:bx+OFFSET SoundBuf).curadr]
  684.     shl    eax,9
  685.     out    dx,ax
  686.     dec    dx
  687.  
  688.     mov    al,0ah
  689.     out    dx,al
  690.  
  691.     inc    dx
  692.     ror    eax,16
  693.     out    dx,ax
  694.     dec    dx
  695.  
  696.     mov    al,0
  697.     out    dx,al
  698.  
  699.     add    dx,2
  700.     mov    al,8
  701.     out    dx,al
  702.     sub    dx,2
  703.  
  704.     REPT    6
  705.     in    al,dx
  706.     ENDM
  707.  
  708.     add    dx,2
  709.     mov    al,8
  710.     out    dx,al
  711.     sub    dx,2
  712.  
  713.  
  714. @@no_loadcur:
  715.  
  716.     test    ch,8
  717.     jnz    @@ramp_vol
  718.  
  719.     jmp    @@ok_vol
  720.  
  721. @@ramp_vol:
  722.  
  723.     mov    al,89h
  724.     out    dx,al
  725.  
  726.     add    dx,2
  727.     in    al,dx
  728.     mov    ah,al
  729.     sub    dx,2
  730.  
  731.     mov    al,7
  732.     out    dx,al
  733.  
  734.     xor    al,al
  735.     mov    ch,[byte ptr ((GUSDATA ptr cs:bx+OFFSET SoundBuf).volume)+1]
  736.  
  737.     cmp    ch,ah
  738.     ja    @@inc_vol2
  739.     mov    al,40h
  740.     xchg    ch,ah
  741. @@inc_vol2:
  742.  
  743.     add    dx,2
  744.     xchg    al,ah
  745.     out    dx,al
  746.     sub    dx,2
  747.  
  748.     mov    al,8
  749.     out    dx,al
  750.  
  751.     add    dx,2
  752.     mov    al,ch
  753.     out    dx,al
  754.     sub    dx,2
  755.  
  756.     mov    al,09h
  757.     out    dx,al
  758.  
  759.     inc    dx
  760.     mov    al,[byte ptr ((GUSDATA ptr cs:bx+OFFSET SoundBuf).volume)]
  761.     out    dx,al
  762.     dec    dx
  763.  
  764.     mov    al,0dh
  765.     out    dx,al
  766.  
  767.     add    dx,2
  768.     mov    al,ah
  769.     out    dx,al
  770.     sub    dx,2
  771.  
  772. @@ok_vol:
  773.     mov    al,1
  774.     out    dx,al
  775.  
  776.     inc    dx
  777.     mov    ax,[(GUSDATA ptr cs:bx+OFFSET SoundBuf).note]
  778.     out    dx,ax
  779.     dec    dx
  780.  
  781.     add    bx,SIZE GUSDATA
  782.  
  783.     dec    cl
  784.     jns    @@next_voice2
  785.  
  786.     and    bx,65535-BUF_LEN
  787.     mov    [cs:OFFSET SoundPtr],bx
  788.  
  789.     pop    dx
  790.     pop    cx
  791.     pop    bx
  792.     pop    eax
  793.  
  794.     jmp    IMAKEMOD
  795.  
  796.  
  797. ENDP
  798.  
  799.  
  800. ;***************************************************************************
  801. ;*    cette routine permet d'arreter l'envoit du son sur la gus
  802.  
  803. PROC    stopgus
  804.  
  805.     mov    dx,[(DEVICE ptr ds:si).port]
  806.  
  807.     mov    ax,14ch        ;Eteint le haut parleur
  808.     call    putcom
  809.  
  810.     sub    dx,103h
  811.     mov    al,3
  812.     out    dx,al
  813.     add    dx,103h
  814.  
  815.     mov    cl,31
  816. @@next_voices:
  817.     dec    dx
  818.     mov    al,cl
  819.     out    dx,al
  820.     inc    dx
  821.  
  822.     mov    ax,0300h    ; 800h loop enable
  823.     call    putcom        ; voice mode
  824.  
  825.  
  826.     mov    ax,030dh        ; stop les volumes ramps
  827.     call    putcom
  828.  
  829.     dec    cl
  830.     jns    @@next_voices
  831.  
  832.     cli
  833.     mov     al,00110110b
  834.     out     43h,al
  835.     xor    al,al
  836.     out     40h,al
  837.     out     40h,al
  838.  
  839.     call    reseteoi
  840.  
  841.     ret
  842.  
  843. ENDP
  844.  
  845. ;***************************************************************************
  846. ;*    Change la vitesse en BPM
  847. ;*
  848. ;* Entrée:
  849. ;*    AL    nouvelle vitesse
  850.  
  851. PROC    defbpmgus
  852.  
  853.     movzx    cx,al
  854.     mov    ax,8426h    ;1193180*2.5
  855.     mov    dx,2dh
  856.     div    cx
  857.     mov    [BPMspeed],ax
  858.     sub    [BPMspeed],RAMPDELAY
  859.  
  860.     movzx    ecx,ax
  861.     mov    eax,80000000h
  862.     xor    edx,edx
  863.     div    ecx
  864.     add    eax,eax
  865.     mov    [ds:Compteur],eax
  866.     mov    [ds:Compte],eax
  867.  
  868.     ret
  869.  
  870. ENDP
  871.  
  872. ;***************************************************************************
  873. ;*    Récupère un l'octet joué par la GUS
  874. ;*
  875. ;* Entrée:
  876. ;*    AL    numero de la voix
  877.  
  878. PROC    peekgus
  879.  
  880.     mov    dx,[(DEVICE ptr ds:bx).port]
  881.     dec    dx
  882.     inc    al
  883.     cli
  884.     out    dx,al
  885.     inc    dx
  886.  
  887.     dec    al
  888.     mov    ah,SIZE VOICE
  889.     mul    ah
  890.     mov    bx,ax
  891.     add    bx,OFFSET Voice1
  892.     push    bx
  893.  
  894.     mov    al,8Ah
  895.     out    dx,al
  896.  
  897.     inc    dx
  898.     in    ax,dx
  899.     mov     bx,ax
  900.     shl    ebx,16
  901.     dec    dx
  902.  
  903.     mov    al,8Bh
  904.     out    dx,al
  905.  
  906.     inc    dx
  907.     in    ax,dx
  908.     mov    bx,ax
  909.     dec    dx
  910.  
  911.     shr    ebx,9
  912.  
  913.     mov    al,43h
  914.     out    dx,al
  915.  
  916.     inc    dx
  917.     mov    ax,bx
  918.     out    dx,ax
  919.     dec    dx
  920.  
  921.     mov    al,44h
  922.     out    dx,al
  923.     add    dx,2
  924.  
  925.     shr    ebx,16
  926.     mov    ax,bx
  927.     out    dx,al
  928.  
  929.     add    dx,2
  930.     in    al,dx
  931.     sub    dx,4
  932.     sti
  933.  
  934.     pop    bx
  935.     mov    dl,[(VOICE PTR ds:bx).volume]
  936.     mul    dl
  937.  
  938.     shr    ax,6
  939.  
  940.     ret
  941.  
  942. ENDP
  943.  
  944. ENDS
  945.  
  946. END